package c.h.a.w;

import android.os.Environment;
import android.text.TextUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;

/* compiled from: AnalyzeFileNode */
public class e {
    public static final String j = Environment.getExternalStorageDirectory().getAbsolutePath();
    public long a;
    public long b;
    public int c = 1;
    public boolean d;
    public String e;
    public String f;
    public e g;
    public Map<String, e> h;
    public List<a> i = new CopyOnWriteArrayList();

    /* compiled from: AnalyzeFileNode */
    public interface a {
        void f(long j, boolean z, e eVar);
    }

    public e(boolean z, String str, e eVar) {
        this.d = z;
        this.e = str;
        this.g = eVar;
        if (z) {
            this.h = new HashMap();
        }
        if (eVar != null) {
            Map map = eVar.h;
            if (map != null) {
                map.put(str, this);
                this.c = eVar.c + 1;
                return;
            }
            throw new IllegalStateException("parent's children must not be null!");
        }
    }

    public void a(long j, boolean z) {
        long j2 = this.a;
        if (j != j2) {
            j2 = j - j2;
            this.a = j;
            e eVar = this.g;
            if (eVar != null) {
                String str = this.e;
                eVar.a(eVar.a + j2, false);
                if (z) {
                    eVar.h.remove(str);
                }
            }
            if (z) {
                Map map = this.h;
                if (map != null) {
                    map.clear();
                }
                this.g = null;
            }
            if (!this.i.isEmpty()) {
                for (a f : this.i) {
                    f.f(j2, z, this);
                }
                if (z) {
                    this.i.clear();
                }
            }
        }
    }

    public String b() {
        if (TextUtils.isEmpty(this.f)) {
            ArrayList arrayList = new ArrayList();
            e eVar = this;
            while (eVar != null && eVar.c != 1) {
                arrayList.add(eVar.e);
                eVar = eVar.g;
            }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(j);
            for (int size = arrayList.size() - 1; size >= 0; size--) {
                stringBuilder.append(File.separator);
                stringBuilder.append((String) arrayList.get(size));
            }
            this.f = stringBuilder.toString();
        }
        return this.f;
    }

    public long c() {
        if (this.d) {
            long j = 0;
            for (Entry value : this.h.entrySet()) {
                j += ((e) value.getValue()).c();
            }
            this.a = j;
        }
        return this.a;
    }
}
